from fastapi import FastAPI
from pydantic import BaseModel
from server.model import gentext,genimg,tts,removebg


app = FastAPI()

class Item(BaseModel):
    prompt: str | None = None
    text: str | None = None
    image: str | None = None

@app.get("/")
async def read_root():
    return {"msg": "SmartWriting is working!"}

# 文章生成
@app.post("/article")
async def article(input: Item):
    output = gentext(input.prompt)
    return {"code":1,"msg": f"{output}!"}

# AI生图
@app.post("/image")
async def image(input: Item):
    output = genimg(input.prompt)
    return {"code":1,"msg": f"{output}!"}

# 文本转语音
@app.post("/voice")
async def voice(input: Item):
    output = tts(input.text)
    return {"code":1,"msg": f"{output}!"}

# 智能抠图
@app.post("/koutu")
async def 抠图(input: Item):
    output = gentext(input.image)
    return {"code":1,"msg": f"{output}!"}